# Python super()使用注意事项
class A:
    def __init__(self):
        print("A", end = " ")
        super().__init__()

class B:
    def __init__(self):
        print("B", end = " ")
        super().__init__()

class C(A, B):
    def __init__(self):
        print("C", end = " ")
        A.__init__(self)
        B.__init__(self)

print("MRO:", [x.__name__ for x in C.__mro__])
C()

class commonBase:
    def __init__(self):
        print("commonBase")
        super().__init__()

class base1(commonBase):
    def __init__(self):
        print("base1")
        super().__init__()

class base2(commonBase):
    def __init__(self):
        print("base2")
        super().__init__()

class myClass(base1, base2):
    def __init__(self, arg):
        print("my base")
        #super().__init__(arg) # TypeError: __init__() takes 1 positional argument but 2 were given

myClass(10)
print()

'''
以下方式虽然能解决问题，但是却是一种很糟糕的解决方法。
由于任何参数都可以传入，所有构造函数都可以接受任何类型的参数，这会导致代码变得脆弱。
'''
class commonBase:
    def __init__(self, *args, **kwargs):
        print("commonBase")
        super().__init__()

class base1(commonBase):
    def __init__(self, *args, **kwargs):
        print("base1")
        super().__init__()

class base2(commonBase):
    def __init__(self, *args, **kwargs):
        print("base2")
        super().__init__()

class myClass(base1, base2):
    def __init__(self, arg):
        print("my base")
        super().__init__(arg)

myClass(10)
